{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "caf4d7f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "#字典\n",
    "vocab = {\n",
    "    '<SOS>': 0,\n",
    "    '<EOS>': 1,\n",
    "    'the': 2,\n",
    "    'quick': 3,\n",
    "    'brown': 4,\n",
    "    'fox': 5,\n",
    "    'jumps': 6,\n",
    "    'over': 7,\n",
    "    'a': 8,\n",
    "    'lazy': 9,\n",
    "    'dog': 10,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5300da6d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<SOS> the quick brown fox jumps over a lazy dog <EOS>\n"
     ]
    }
   ],
   "source": [
    "#添加首尾符号\n",
    "sent = 'the quick brown fox jumps over a lazy dog'\n",
    "\n",
    "sent = '<SOS> ' + sent + ' <EOS>'\n",
    "\n",
    "print(sent)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d0ba7c75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['<SOS>', 'the', 'quick', 'brown', 'fox', 'jumps', 'over', 'a', 'lazy', 'dog', '<EOS>']\n"
     ]
    }
   ],
   "source": [
    "#英文分词\n",
    "words = sent.split()\n",
    "\n",
    "print(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7ee7b019",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1]\n"
     ]
    }
   ],
   "source": [
    "#编码为数字\n",
    "encode = [vocab[i] for i in words]\n",
    "\n",
    "print(encode)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
